package com.mediator.dispatcher.extend;

import com.mediator.concrete.People;
import com.mediator.dispatcher.Mediator;

import java.util.ArrayList;
import java.util.List;

public class ConcreteMediator extends Mediator {

    private List<People> people = new ArrayList<>();

    @Override
    public void register(People ppl) {
        if ( !people.contains(ppl) ) {
            people.add(ppl);
            ppl.setMediator(this);
        }
    }

    @Override
    public void relay(People ppl, String msg) {
        for (People ob : people) {
            if ( !ob.equals(ppl) ) {
                ob.receive(msg);
            }
        }
    }
}
